/* 
 * File:   AbstractALSource.cpp
 * Author: RedEyedKiller
 * 
 * Created on 23 Αύγουστος 2011, 3:53 πμ
 */

#include "AbstractALSource.h"

namespace al
{

AbstractALSource::AbstractALSource(ALuint id)
{
    sourceId = id;
    numOfLoops = 0;
}

AbstractALSource::~AbstractALSource()
{
}

void AbstractALSource::Play()
{
    alSourcePlay( sourceId );
}

bool AbstractALSource::IsPlaying()
{
    ALint iState;
    alGetSourcei( sourceId, AL_SOURCE_STATE, &iState );
    return iState == AL_PLAYING;
}

bool AbstractALSource::IsPaused()
{
    ALint iState;
    alGetSourcei( sourceId, AL_SOURCE_STATE, &iState );
    return iState == AL_PAUSED;
}

bool AbstractALSource::IsStopped()
{
    ALint iState;
    alGetSourcei( sourceId, AL_SOURCE_STATE, &iState );
    return iState == AL_STOPPED;
}

void AbstractALSource::Pause()
{
    alSourcePause( sourceId );
}

void AbstractALSource::Stop()
{
    alSourceStop( sourceId );
}

void AbstractALSource::Rewind()
{
    alSourceRewind( sourceId );
}

float AbstractALSource::GetPitch()
{
    float value;
    alGetSourcef( sourceId, AL_PITCH, &value );
    return value;
}

void AbstractALSource::SetPitch(float pitch)
{
    alSourcef( sourceId, AL_PITCH, pitch );
}

float AbstractALSource::GetGain()
{
    float value;
    alGetSourcef( sourceId, AL_GAIN, &value );
    return value;
}

void AbstractALSource::SetGain(float gain)
{
    alSourcef( sourceId, AL_GAIN, gain );
}

ALuint AbstractALSource::GetRawSource()
{
    return sourceId;
}

void AbstractALSource::SetLooping(bool loop)
{
    alSourcei( sourceId, AL_LOOPING, loop );
}

void AbstractALSource::SetNumOfLoops(int numOfLoops)
{
    this->numOfLoops = numOfLoops;
}

int AbstractALSource::GetNumOfLoops() const
{
    return numOfLoops;
}

bool AbstractALSource::IsLooping()
{
    int value;
    alGetSourcei( sourceId, AL_LOOPING, &value );
    return static_cast < bool > ( value );
}

ALuint AbstractALSource::GetSourceState()
{
    ALint state;
    alGetSourcei( sourceId, AL_SOURCE_STATE, &state );
    return state;
}

}
